﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
namespace ZLDC.Estate.Quantify.ajax
{
    public partial class GetUser : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                string type = Request.QueryString["type"];
                if (type == "1")
                {
                    if (Request.QueryString["uname"] != null)
                    {
                        string result = HttpUtility.UrlDecode(Request.QueryString["uname"].Trim());
                        Response.Write(GetNewUserDept(result));
                        Response.End();
                    }
                }
                if (type == "2")
                {
                    if (Request.QueryString["uname"] != null)
                    {
                        string result = HttpUtility.UrlDecode(Request.QueryString["uname"].Trim());
                        Response.Write(GetDistrict(result));
                        Response.End();
                    }
                }
            }

            

        }
        private String GetNewUserDept(String prefixText)
        {
            StringBuilder sbstr = new StringBuilder();
            //select * from kfb.t_s_tmp_usr where dltflg=0
            string sSql = " select name from t_estate where 1=1";

            string sKey = prefixText.Replace("'", "''");
            //关键字

            string attfsg = "";
            string Attribution = "深圳";

            // sSql += " and   u.fgs = '" + sKey + "' ";
            sSql += " and (name like N'" + sKey + "%' or namePy like N'" + sKey + "%' or id like N'" + sKey + "%')";
            System.Data.DataTable dt = ZLDC.Topo.BLL.Estate.lp_Basis.Getds(sSql).Tables[0]; //DataBase.Query(sSql).Tables[0];
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                sbstr.Append(dt.Rows[i]["name"].ToString());

                sbstr.Append("\n");
            }
            return sbstr.ToString();
        }

        private String GetDistrict(String prefixText)
        {
            StringBuilder sbstr = new StringBuilder();
            //select * from kfb.t_s_tmp_usr where dltflg=0
            string sSql = " select top 50 * from t_zlhq_t_s_alldept   where DltFlg=0";

            string sKey = prefixText.Replace("'", "''");
            //关键字

            string attfsg = "";
            string Attribution = "深圳";

            // sSql += " and   u.fgs = '" + sKey + "' ";
            sSql += " and (name like N'" + sKey + "%' or py like N'" + sKey + "%' or id like N'" + sKey + "%')";
            System.Data.DataTable dt = ZLDC.Topo.BLL.Estate.lp_Basis.Getds(sSql).Tables[0]; //DataBase.Query(sSql).Tables[0];
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                sbstr.Append(dt.Rows[i]["name"].ToString() + "[" + dt.Rows[i]["id"].ToString() + "]");

                sbstr.Append("\n");
            }
            return sbstr.ToString();
        }
    }
}
